package com.app.Cutofftime;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AssItem {
    private String title;
    private String module;
    private String date;
    private String endTime;
    private String reTime;
    private String type;
    private String dec;
    private int proportion;
    private int id;
    public AssItem(String title, String module,String date,
                   String endTime,int id,String type,
                   int proportion,String dec){
        this.title = title;
        this.module = module;
        this.endTime = endTime;
        this.id = id;
        this.date = date;
        this.type = type;
        this.proportion = proportion;
        this.dec = dec;
    }

    public String getDec() {
        return "Description: " + dec;
    }

    public String getProportion(){
        return "Proportion: " + proportion;
    }

    public String getType(){
        return type;
    }

    public String getTitle() {
        return title;
    }

    public String getModule() {
        return module;
    }

    public String getEndTime() {
        return date + " " + endTime;
    }

    public String getReTimeStr() {
        String time=getEndTime() + ":00";
//        String time="2010-11-20 11:10:10";
        String time1= gitNow();
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = formatter.parse(time);
            Date date1 = formatter.parse(time1);
            long diff =  date.getTime() - date1.getTime();
            long hours = diff/ (1000 * 60 * 60);
            long days = 0;
            String str1 = "";
            String str2 = " Hours";
            String str3 = " Day,";
            if(diff>=0){
                str1 = "Time remaining: ";
            }else {
                str1 = "Overdue: ";
            }
            if(hours>24||hours<-24) {
                days = hours/24;
                hours = hours%24;
                reTime = str1 + String.valueOf(days) + str3 + String.valueOf(hours) + str2;
            }else{
                reTime = str1 + String.valueOf(hours) + str2;
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return reTime;
    }

    public Long getReTime() {
        String time=getEndTime() + ":00";
//        String time="2010-11-20 11:10:10";
        String time1= gitNow();
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long hours = 0;
        try {
            Date date = formatter.parse(time);
            Date date1 = formatter.parse(time1);
            long diff =  date.getTime() - date1.getTime();
            hours = diff/ (1000 * 60 * 60);

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return hours;
    }


    public int getId() {
        return id;
    }

    public String gitNow(){
        Date date=new Date();
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time=formatter.format(date);
        return time;
    }

    public String getColor(){
        if(getReTime()<0)
            return "#a7324a";
        return "#336666";
    }
}
